import React, { Component } from 'react'
import {add, request} from '../store/actions'
import {connect} from 'react-redux'


/**
 * UI组件
 */
class Comp2 extends Component {

  render() {
    console.log('this.props =========>', this.props);

    let {count, name, add, request} = this.props
    return (
      <div>
        <h2>{count}</h2>
        <button onClick={add}>add</button>
        <h2>{name}</h2>
        <button onClick={request}>request</button>
      </div>
    )
  }
}

/**
 * react-redux 容器组件
 */

function mapStateToProps(state) {
  return {
    count: state.count,
    name: state.name
  }
}

let mapDispatchToProps = {
  add,
  request
}

export default connect(mapStateToProps, mapDispatchToProps)(Comp2)
